package com.chd.ledger_server.service.impl;

import com.chd.ledger_server.entity.ModelBaseModels;
import com.chd.ledger_server.dao.ModelBaseModelsDao;
import com.chd.ledger_server.service.ModelBaseModelsService;
import com.chd.ledger_server.domain.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基础模型表(ModelBaseModels)表服务实现类
 *
 * @author makejava
 * @since 2025-07-18 19:54:17
 */
@Service("modelBaseModelsService")
public class ModelBaseModelsServiceImpl implements ModelBaseModelsService {
    @Resource
    private ModelBaseModelsDao modelBaseModelsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param baseId 主键
     * @return 实例对象
     */
    @Override
    public ModelBaseModels queryById(Integer baseId) {
        return this.modelBaseModelsDao.queryById(baseId);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo queryAllModelBaseModelssByPage(PageDto pageDto) {
        //空值处理
        if (pageDto.getPage() == null || pageDto.getSize() == null) {
            pageDto.setPage(1);
            pageDto.setSize(10);
        }
        PageHelper.startPage(pageDto.getPage(), pageDto.getSize());
        List<ModelBaseModels> list = modelBaseModelsDao.queryAll(pageDto.getModelBaseModels());
        PageInfo<ModelBaseModels> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param modelBaseModels 实例对象
     * @return 实例对象
     */
    @Override
    public ModelBaseModels insert(ModelBaseModels modelBaseModels) {
        this.modelBaseModelsDao.insert(modelBaseModels);
        return modelBaseModels;
    }

    /**
     * 修改数据
     *
     * @param modelBaseModels 实例对象
     * @return 实例对象
     */
    @Override
    public ModelBaseModels update(ModelBaseModels modelBaseModels) {
        this.modelBaseModelsDao.update(modelBaseModels);
        return this.queryById(modelBaseModels.getBaseId());
    }

    /**
     * 通过主键删除数据
     *
     * @param baseId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer baseId) {
        return this.modelBaseModelsDao.deleteById(baseId) > 0;
    }
}
